<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<table cellpadding="5" style="margin-left: 30px" id="itemParamAddTable" class="itemParam">
	<tr class="hide addGroupTr">
		<td>属性参数:</td>
		<td>
			<ul>
				<li><a href="javascript:void(0)" class="easyui-linkbutton addProperty">添加属性</a></li>
			</ul>
		</td>
	</tr>
	<tr>
		<td></td>
		<td>
			<a href="javascript:void(0)" class="easyui-linkbutton submit">提交</a>
	    	<a href="javascript:void(0)" class="easyui-linkbutton close">关闭</a>
		</td>
	</tr>
  </table>
  
  <div  class="itemParamAddTemplate" style="display: none;">
	<li class="param">
		<ul>
			<li>
				<input  style="width: 150px;" class="easyui-textbox" name="param"/>&nbsp;<a href="javascript:void(0)" class="easyui-linkbutton delParam" title="删除" data-options="plain:true,iconCls:'icon-cancel'"></a>						
			</li>
		</ul>
	</li>
</div>
<script type="text/javascript">
$(function(){
	var param=$('#propertyData').datagrid('getRows')[0];
	var paramDataJson=$.parseJSON(param.gpParamData)
	$.each(paramDataJson, function(idx, obj) {
		$(".itemParamAddTemplate [name=param]").val(eval(paramDataJson)[idx]);
		 var temple = $(".itemParamAddTemplate li").eq(1).clone();
		 
		 $(".addProperty").parent().parent().append(temple); 
	});
	$(".itemParamAddTemplate [name=param]").val("");
	$(".addProperty").click(function(){
 		var temple = $(".itemParamAddTemplate li").eq(1).clone();
		 
		
		 temple.find(".delParam").click(function(){
			  $(this).parent().remove();
		  });
		 $(".addProperty").parent().parent().append(temple); 
	});
	
	$("#itemParamAddTable").find(".delParam").click(function(){
		  $(this).parent().remove();
	  });
	
	
	$("#itemParamAddTable .close").click(function(){
		$(".panel-tool-close").click();
	});
	$("#itemParamAddTable .submit").click(function(){
		var params = [];
		var groups = $("#itemParamAddTable [name=param]");
		groups.each(function(i,e){
			var _val = $(e).siblings("input").val();
			if($.trim(_val).length>0){
				params.push(_val);	
			}
		});
		var url = "property/updatePropertyParam/"+param.gpId;
		$.post(url,{"paramData":JSON.stringify(params)},function(data){
			try{
				if(data.status == 200){
					$.messager.alert('提示','编辑商品属性成功!',undefined,function(){
						$(".panel-tool-close").click();
    					$("#propertyData").datagrid("reload");
    				});
				}else if(data.status==403){
					$.messager.alert('提示','提交参数错误!','info');
				}
			}catch (e) {
				$.messager.alert('提示','操作失败!','info');
				$(".panel-tool-close").click();
			}
			
		}); 
	});
	
	
});


</script>